# 导包
import requests
# 创建封装的接口类
import app
class IHRMAPI:
    def __init__(self):
        # 定义登陆的URL
        self.login_url = app.BASE_URL + "/api/sys/login"
        self.add_emp_url = app.BASE_URL + "/api/sys/user"

    def login(self, request_body):
        return requests.post(url=self.login_url,
                             headers=app.HEADERS,
                             json=request_body)

    # 封装添加员工
    def add_emp(self, request_body):
        return requests.post(url=self.add_emp_url,
                             headers=app.HEADERS,
                             json=request_body)
    # 封装查询员工
    def query_emp(self, emp_id):
        query_url = self.add_emp_url + "/" + emp_id
        print("查询员工的URL为：", query_url)
        return requests.get(url=query_url, headers=app.HEADERS)

    # 封装修改员工
    def modify_emp(self, emp_id, request_body):
        modify_url =self.add_emp_url + "/" + emp_id
        print("修改员工的URL为：", modify_url)
        return requests.put(url=modify_url,
                            headers=app.HEADERS,
                            json=request_body)

    # 封装删除员工
    def delete_emp(self, emp_id):
        delete_url = self.add_emp_url + "/" + emp_id
        print("删除员工的URL为：", delete_url)
        return requests.delete(url=delete_url, headers=app.HEADERS)

# # 调试封装的登陆接口
# ihrm_api = IHRMAPI() # 实例化封装的类
# request_body = {"mobile":"13800000002", "password":"123456"} # 定义请求体
# response = ihrm_api.login(request_body) # 发送登陆接口请求
# print(response.text) # 打印文本格式响应体